package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.PushTagRelationUser;
import com.sc.nft.mapper.PushTagRelationUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author 刘国航
 * @desc
 * @since 2024/6/14 11:51
 */
@Slf4j
@Repository
public class PushTagRelationUserDao extends ServiceImpl<PushTagRelationUserMapper, PushTagRelationUser> {

    public List<PushTagRelationUser> getListByPushTagIdList(List<Long> pushTagIdList) {
        LambdaQueryWrapper<PushTagRelationUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(PushTagRelationUser::getPushTagId, pushTagIdList);
        return baseMapper.selectList(queryWrapper);
    }

    public List<PushTagRelationUser> getListByPushTagIdAndUserIdList(Long pushTagId, List<Long> userIdList) {
        LambdaQueryWrapper<PushTagRelationUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PushTagRelationUser::getPushTagId, pushTagId);
        queryWrapper.in(PushTagRelationUser::getUserId, userIdList);
        return baseMapper.selectList(queryWrapper);
    }

    public PushTagRelationUser getOneByPushTagIdAndUserId(Long pushTagId, Long userId) {
        LambdaQueryWrapper<PushTagRelationUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PushTagRelationUser::getPushTagId, pushTagId);
        queryWrapper.eq(PushTagRelationUser::getUserId, userId);
        return baseMapper.selectOne(queryWrapper);
    }

    public List<PushTagRelationUser> getListByPushTagId(Long pushTagId) {
        LambdaQueryWrapper<PushTagRelationUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PushTagRelationUser::getPushTagId, pushTagId);
        return baseMapper.selectList(queryWrapper);
    }

    public Page<PushTagRelationUser> pageByTagIdAndTel(Page<PushTagRelationUser> page, Long pageTagId, String userTel) {
        LambdaQueryWrapper<PushTagRelationUser> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PushTagRelationUser::getPushTagId, pageTagId);
        queryWrapper.eq(StrUtil.isNotBlank(userTel), PushTagRelationUser::getUserTel, userTel);
        queryWrapper.orderByDesc(PushTagRelationUser::getId);
        return baseMapper.selectPage(page, queryWrapper);
    }

}
